<!-- 整体统计 -->
<template>
  <div class="totalStatistics">
    <div v-for="(item, index) in list" :key="index" class="cardBox">
      <div>
        <p>{{ item.name }}</p>
        <div class="num">{{ numberTransactions(form[item.filed]) + (item.dit || '') }}</div>
      </div>

      <img :src="item.img" alt="" v-if="item.img">
    </div>
  </div>
</template>

<script>
import { getOverview } from "@/api/home";
export default {
  name: "TotalStatistics",
  data() {
    return {
      list: [
        { name: "交易总额", filed: "transAmount", img: require("@/assets/home/zjye.png") },
        { name: "交易数", filed: "transCount", bg: require("@/assets/home/zjye.png") },
        { name: "入住商户数", filed: "merchantCount", img: require("@/assets/home/rzshs.png") },
        { name: "会员用户数", filed: "customerCount", img: require("@/assets/home/hyyhs.png") },
        { name: "推广渠道费用", filed: "platformIncome", img: require("@/assets/home/qdtgf.png") },
      ],
      form: {
        transCount: 0,
        transAmount: 0,
        merchantCount: 0,
        customerCount: 0,
        platformIncome: 0
      }
    };
  },
  created() {
    this.getOverview();
  },
  methods: {
    //格式转换，如：123456789 -->>> 123,456,789
    numberTransactions(num) {
      return Number(num).toLocaleString();
    },
    getOverview() {
      getOverview({}).then(res => {
        this.form = { ...res.data };
      });
    }
  }
};
</script>

<style lang="scss">
.totalStatistics {
  display: grid;
  grid-gap: 40px;
  grid-template-columns: repeat(5, 1fr);
  height: 100%;

  .cardBox {
    background: #fff;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    padding-right: 30px;
    font-family: "Arial Negreta", "Arial Normal", "Arial", sans-serif;

    p {
      color: #859da9;
    }

    .num {
      font-weight: 700;
      font-style: normal;
      color: #344650;
      font-size: 28px;
      margin-top: 10px;
    }
  }
}
</style>
